package org.zcl.service.tx.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.zcl.entity.TbUnion;
import org.zcl.entity.TbUnionChannel;
import org.zcl.service.TbUnionChannelService;
import org.zcl.service.TbUnionService;
import org.zcl.service.tx.TbUnionTxService;

import java.util.List;

/**
 * @Package org.zcl.service.tx.impl
 * @PROJECT_NAME: question
 * @DESCRIPTION:
 * @USER: zhuchenglin
 * @DATE: 2022/6/21 10:32
 */
@Slf4j
@Service
public class TbUnionTxServiceImpl implements TbUnionTxService {

    @Autowired
    private TbUnionService tbUnionService;

    @Autowired
    private TbUnionChannelService tbUnionChannelService;

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public List<TbUnion> insertTx(List<TbUnion> tbUnionList, TbUnionChannel tbUnionChannel) {
        tbUnionChannelService.insert(tbUnionChannel);
        for (TbUnion tbUnion : tbUnionList) {
            tbUnionService.insertUnion(tbUnion);
        }
        if (tbUnionChannel.getUnionId() == 17) {
            throw new RuntimeException("asfd");
        }
        return tbUnionService.getUnionList();
    }
}
